package com.tianqu.tms.www.bid.controller;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.entity.AucManagement;
import com.tianqu.tms.www.bid.viewhelper.BidCarSerchAllBidDetailViewHelper;

public class BidCarSerchAllDoneResultController extends TmsController {
	private static String ID = "id";
	private static String DONEPRICESD = "donePrices";
	private static String MEMBERID = "memberId";
	private static String SERIAL = "serial";
	private static String FLG = "flg";
	private static String BIDSTATUS = "bidStatus";
	private Logger logger = Logger
			.getLogger(BidCarSerchAllDoneResultController.class);

	@Override
	public void execute(UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();

		// 添加事务提交异常捕获
		try {
			controller.begin();
			String id = (String) uc.getAttribute(ID);

			AucManagement aucManagement = AucManagement.getInstance();
			aucManagement.setId(Integer.valueOf(id));
			aucManagement.setBidStatus(StringUtil.getint(uc.getParameter(BIDSTATUS)));// 成交状态取得 modify by mufeiyu
			aucManagement.setDonePrices(StringUtil.getint(uc.getParameter(DONEPRICESD)));
			aucManagement.setDoneMemberId(uc.getParameter(MEMBERID));
			aucManagement.updateAucManageInfo(aucManagement);
			
			BidCarSerchAllBidDetailViewHelper view = new BidCarSerchAllBidDetailViewHelper();
			
			view.setId(StringUtil.getint(String.valueOf(uc.getAttribute(ID))));
			
			logger.debug(this.getClass().getName() + "#execute was completed.");
			controller.commit();
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			// 系统异常
			if (e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}

	}
}
